package com.yike.user.controller;

import com.yike.user.param.PlatformRoleParam;
import com.yike.user.service.PlatformRoleService;
import com.yike.user.vo.PlatformRoleVo;
import lombok.extern.slf4j.Slf4j;
import com.yike.user.param.PlatformRolePageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 平台角色 控制器
 *
 * @author Sakura
 * @since 2024-10-29
 */
@Slf4j
@RestController
@RequestMapping("/platform/role")
@Module("user")
@Api(value = "平台角色API", tags = {"平台角色"})
public class PlatformRoleController extends BaseController {

    @Autowired
    private PlatformRoleService platformRoleService;

    /**
     * 添加平台角色
     */
    @PostMapping("/add")
    @OperationLog(name = "添加平台角色", type = OperationLogType.ADD)
    @ApiOperation(value = "添加平台角色", response = ApiResult.class)
    public ApiResult<Boolean> addPlatformRole(@Validated(Add.class) @RequestBody PlatformRoleParam platformRoleParam) throws Exception {
        boolean flag = platformRoleService.savePlatformRole(platformRoleParam);
        return ApiResult.result(flag);
    }

    /**
     * 修改平台角色
     */
    @PostMapping("/update")
    @OperationLog(name = "修改平台角色", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改平台角色", response = ApiResult.class)
    public ApiResult<Boolean> updatePlatformRole(@Validated(Update.class) @RequestBody PlatformRoleParam platformRoleParam) throws Exception {
        boolean flag = platformRoleService.updatePlatformRole(platformRoleParam);
        return ApiResult.result(flag);
    }

    /**
     * 删除平台角色
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除平台角色", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除平台角色", response = ApiResult.class)
    public ApiResult<Boolean> deletePlatformRole(@PathVariable("id") Long id) throws Exception {
        boolean flag = platformRoleService.deletePlatformRole(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取平台角色详情
     */
    @GetMapping("/info/{id}")
    //@OperationLog(name = "平台角色详情", type = OperationLogType.INFO)
    @ApiOperation(value = "平台角色详情", response = PlatformRoleVo.class)
    public ApiResult<PlatformRoleVo> getPlatformRole(@PathVariable("id") Long id) throws Exception {
        PlatformRoleVo platformRoleVo = platformRoleService.getPlatformRole(id);
        return ApiResult.ok(platformRoleVo);
    }

    /**
     * 平台角色分页列表
     */
    @PostMapping("/getPageList")
    //@OperationLog(name = "平台角色分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "平台角色分页列表", response = PlatformRoleVo.class)
    public ApiResult<Paging<PlatformRoleVo>> getPlatformRolePageList(@Validated @RequestBody PlatformRolePageParam platformRolePageParam) throws Exception {
        Paging<PlatformRoleVo> paging = platformRoleService.getPlatformRolePageList(platformRolePageParam);
        return ApiResult.ok(paging);
    }

}

